module.exports = (date) => {
  let fmt = "yyyy-MM-dd hh:mm:ss";
  function timeFormat(num) {
    return num < 10 ? '0' + num : num;
  }
  const o = {
    "M+": timeFormat(date.getMonth() + 1),
    "d+": timeFormat(date.getDate()),
    "h+": timeFormat(date.getHours()),
    "m+": timeFormat(date.getMinutes()),
    "s+": timeFormat(date.getSeconds()),
    "q+": Math.floor((date.getMonth() + 3) / 3),
    "S+": date.getMilliseconds(),
  };

  if(/(y+)/.test(fmt)){
    fmt = fmt.replace(RegExp.$1, date.getFullYear())
  }
  for(let k in o){
    if(new RegExp('(' +k + ')').test(fmt)) {
      //fmt = fmt.replace(RegExp.$1, o[k].toString().length === 1 ? '0' + o[k] : o[k])
      fmt = fmt.replace(RegExp.$1,o[k])
    }
  }
  
  return fmt;
}
